package com.campus.counseling.controller;

import com.campus.counseling.model.common.Result;
import com.campus.counseling.entity.SysRole;
import com.campus.counseling.service.SysRoleMenuService;
import com.campus.counseling.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "角色管理")
@RestController
@RequestMapping("/api/role")
@RequiredArgsConstructor
public class RoleController {
    
    private static final Logger log = LoggerFactory.getLogger(RoleController.class);
    
    private final SysRoleService roleService;
    private final SysRoleMenuService roleMenuService;

    @ApiOperation("获取角色列表")
    @GetMapping("/list")
    public Result<List<SysRole>> list() {
        return Result.success(roleService.list());
    }

    @ApiOperation("获取角色菜单")
    @GetMapping("/{roleId}/menus")
    public Result<List<Long>> getRoleMenus(@PathVariable Long roleId) {
        log.info("获取角色菜单, roleId: {}", roleId);
        return Result.success(roleMenuService.getMenuIdsByRoleId(roleId));
    }

    @ApiOperation("更新角色菜单")
    @PutMapping("/{roleId}/menus")
    public Result<Void> updateRoleMenus(@PathVariable Long roleId, @RequestBody List<Long> menuIds) {
        log.info("更新角色菜单, roleId: {}, menuIds: {}", roleId, menuIds);
        roleMenuService.updateRoleMenus(roleId, menuIds);
        return Result.success();
    }
} 